package com.yidu.hbats.action.emp;

import com.yidu.hbats.model.AtsEmpAthlete;
import com.yidu.hbats.service.emp.AtsEmpAthleteService;
import com.yidu.utils.Message;
import com.yidu.utils.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: hbats
 * @description: 运动员信息控制器
 * @author: 张超
 * @create: 2019-10-29 18:39
 */

@Controller
@RequestMapping("AtsEmpAthleteController")

public class AtsEmpAthleteController {

    /**
     * 运动员信息接口
     */
    @Resource
    private AtsEmpAthleteService atsEmpAthleteService;

    @RequestMapping("insertOrUpdate")
    @ResponseBody
    public Message insertOrUpdate(AtsEmpAthlete atsEmpAthlete){

        if(atsEmpAthlete.getAthleteId()!=null){//有ID是修改

        }else{
            atsEmpAthlete.setIsva(1);//是否有效
            Date date = new Date();
            atsEmpAthlete.setCreatTime(date);//创建时间
        }

        atsEmpAthleteService.saveOrUpdate(atsEmpAthlete);

        Message message = new Message();
        message.setNum(1);
        message.setMsg("编辑成功");
        return message;
    }


    /**
     * 根据id查找
     * @param id
     * @return
     */
    @RequestMapping("findById")
    @ResponseBody
    public AtsEmpAthlete findById(Integer id){
        return atsEmpAthleteService.findById(id);
    }


    /**
     * 查询所有  返回map
     * @param atsEmpAthlete
     * @param page
     * @return
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public Map selectAll(AtsEmpAthlete atsEmpAthlete, Page page){
        Map map = new HashMap();
        List<AtsEmpAthlete> list = atsEmpAthleteService.selectAll(atsEmpAthlete,page);

        int count = atsEmpAthleteService.selectCount(atsEmpAthlete);
        //int count = 10;
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", list);
        return map;
    }

    /**
     * 按id删除
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public Message delete(Integer id){
        Message message = new Message();
        if(id==null){
            message.setNum(0);
            message.setMsg("删除失败");
            return message;
        }else{
            AtsEmpAthlete atsEmpAthlete = new AtsEmpAthlete();
            atsEmpAthlete.setAthleteId(id);
            atsEmpAthlete.setIsva(2);
            atsEmpAthleteService.saveOrUpdate(atsEmpAthlete);

            message.setNum(1);
            message.setMsg("删除成功");
            return message;
        }


    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("deleteAll")
    @ResponseBody
    public Message deleteAll(String ids){
        Message message = new Message();
        if(atsEmpAthleteService.deleteAll(ids)==0){
            message.setNum(0);
            message.setMsg("删除失败");
        }else{
            message.setNum(1);
            message.setMsg("删除成功");
        }
        return message;
    }

    /**
     * 查询所有  返回list
     * @param atsEmpAthlete
     * @return
     */
    @RequestMapping("findAll")
    @ResponseBody
    public List<AtsEmpAthlete> findAll(AtsEmpAthlete atsEmpAthlete){
        return atsEmpAthleteService.findAll(atsEmpAthlete);
    }

    /**
     * 根据训练项目ID查询运动员  返回list
     * @param atsEmpAthlete
     * @return
     */
    @RequestMapping("selectBysportId")
    @ResponseBody
    public List<AtsEmpAthlete> selectBysportId(AtsEmpAthlete atsEmpAthlete){
        return atsEmpAthleteService.selectBysportId(atsEmpAthlete);
    }


    /**
     * 根据教练员ID查询运动员  返回list
     * @param atsEmpAthlete
     * @return
     */
    @RequestMapping("selectByCoachId")
    @ResponseBody
    public List<AtsEmpAthlete> selectByCoachId(AtsEmpAthlete atsEmpAthlete){
        return atsEmpAthleteService.selectByCoachId(atsEmpAthlete);
    }
}